package com.wuji1626.spark.rdd.transform

import org.apache.spark.{SparkConf, SparkContext}

object RDD_Transform_repartition {

  def main(args: Array[String]): Unit = {
    // Step1: 准备环境
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)
    // Step2: 算子 repartition
    val rdd = sc.makeRDD(List(1, 2, 3, 4, 5, 6), numSlices = 2)
    // coalesce 能够扩大分区，但是不 shuffle 不会打乱数据，新分区为空
    val repartitionRDD = rdd.repartition(3)
    repartitionRDD.saveAsTextFile("output")
    // Step3: 关闭环境
    sc.stop()
  }

}
